package com.hzit.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * 类名：
 * 作者：WF
 * 功能：mybatis工具类的对象
 */
public class MybatisUtil {
	//1. 得到sqlSessionFactory对象
	public static SqlSessionFactory getSqlSessionFactory() throws IOException {
		String resource = "mybatis/mybatis-config.xml";
		InputStream inputStream = Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
		return sqlSessionFactory;
	}
	//2. 得到sqlSession对象
	// public SqlSession getSqlSession(boolean autoCommit){
	// 	try {
	// 		//2.1 得到SqlSessionFactory对象
	// 		SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
	// 		//2.2 返回SqlSession
	// 		return sqlSessionFactory.openSession(autoCommit);
	// 	} catch (IOException e) {
	// 		e.printStackTrace();
	// 	}
	// 	return null;
	// }
}
